<?php 
class Login extends Controller {

	function Login()
	{
		parent::Controller();
		$this->load->library('layout', 'layouts/layout_login');
	}
	/* definir accion  */
	function index()
	{
		
		if(!$this->uri->segment(3))
		{
			$action = 'home/index';
			
		}else
		{
			$action = $this->uri->segment(3)."/".$this->uri->segment(4);

		}

		$data['action'] = $action;
		
		$this->layout->view('login/index', $data);
	}
	
	function verify(){
		$result_ = $this->authentication->login($this->input->post("username"),$this->input->post("password"));
		if ($result_) {
			
			$this->load->database();
			$sql="SELECT nombre FROM rol WHERE id_rol IN
(SELECT id_rol FROM perfil WHERE id_usuario=(SELECT id_usuario FROM usuario WHERE login='".$this->input->post("username")."' AND password='".$this->input->post("password")."'))";
$result_set=$this->db->query($sql);
foreach ($result_set->result() as $row)
{    $rol=$row->nombre;   }

if($rol=='administrador')
redirect('home/index');
else if($rol=='project')
redirect('home/project');
else if($rol=='employed')
redirect('home/employed');
			//redirect($this->input->post("action"));
		} else {
		//	redirect('login/index');
			echo "no exixte valida";

		}
	}
	
	function logout()
	{
		$this->authentication->logout();
		redirect("admin/login/index");//envia aca luego se matar sesion
	}
}
?>